/**
 * Created by 叶子 on 2017/8/13.
 */
import React, {Component} from 'react';
import {Route, Redirect, Switch} from 'react-router-dom';
import AllPage from '../pageComponent/index';
import routesConfig from './config';

export default class CRouter extends Component {

  render() {
    return (
      <Switch>
        {
          Object.keys(routesConfig).map(key =>
            routesConfig[key].map(r => {
              const route = r => {
                const Component = AllPage[r.component];
                return (
                  <Route
                    key={r.route || r.key}
                    exact
                    path={r.route || r.key}
                    render={props =>
                      <Component
                        {...props} />
                    }
                  />
                )
              }
              return r.component ? route(r) : r.subs.map(r => route(r));
            })
          )
        }

        <Route render={() => <Redirect to="/404"/>}/>
      </Switch>
    )
  }
}
